package Homework5

import java.time.Instant

import akka.actor.Actor

import scala.collection.mutable


class MasterCheck extends Actor {
  var instant: Instant = _
  override def receive: Receive = {
    case workerMap: mutable.HashMap[String, Instant] => {
      while (true){
        instant = Instant.now()
        val timeStamp = instant.toEpochMilli
        for (worker <- workerMap){
          if (timeStamp - worker._2.toEpochMilli > 1000){
            println("删除" + worker._1)
            workerMap.remove(worker._1)
          }
        }
        Thread.sleep(1000)
      }
    }
  }
}
